#!/usr/bin/env bash

if [ $UID -ne 0 ]; then
    echo "Superuser privileges are required to run this script."
    echo "e.g. \"sudo $0\""
    exit 1
fi

#拉取镜像，spring boot2.2.x支持的最高版本
docker pull elasticsearch:6.8.6

#启动镜像
docker run --name=elasticsearch -d -e TZ="Asia/Shanghai" -p 9200:9200 -p 9300:9300 -v /opt/es/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml elasticsearch:6.8.6

#进入镜像，设置用户名密码  bin/elasticsearch-setup-passwords interactive

#安装ik分词器
docker cp /opt/es/ik local-es:/usr/share/elasticsearch/plugins/

#重新启动
docker restart local-es

#安装ElasticHD
docker pull containerize/elastichd
#link 后面的是别名，连接的时候会使用这个别名    http://username:password@elasticsearch:9200
docker run -p 9800:9800 -d -e TZ="Asia/Shanghai" --name=elastichd --restart=always --link local-es:elasticsearch containerize/elastichd

#安装Kibana
docker pull kibana:6.8.6
docker run -d -e TZ="Asia/Shanghai" --link local-es:elasticsearch --name=kibana -p 5601:5601 -v /Users/Allan/Develop/Deploys/elasticsearch/kibana.yml:/usr/share/kibana/config/kibana.yml kibana:6.8.6

#安装logstash
docker pull logstash:6.8.6
docker run -d -e TZ="Asia/Shanghai" --restart=always --link local-es:elasticsearch -p 5044:5044 --name logstash -v /Users/Allan/Develop/Deploys/elasticsearch/logstash/logstash.yml:/usr/share/logstash/config/logstash.yml -v /Users/Allan/Develop/Deploys/elasticsearch/logstash/conf.d/:/usr/share/logstash/conf.d/ logstash:6.8.6
docker run -d -e TZ="Asia/Shanghai" --restart=always --link local-es:elasticsearch -p 5044:5044 --name logstash logstash:6.8.6

#执行logstash
docker exec -it logstash bash -c 'nohub /usr/share/logstash/bin/logstash -f /usr/share/logstash/conf.d/logstash.conf &'